<template>
  <div class="addNewAddress-body">
    <custom title="新增地址" />
    <div class="addNewAddress-header"></div>
    <div class="addNewAddress-main">
      <van-field v-model="state.text" clearable label="联系人 " placeholder=" 请输入您的姓名" />
      <van-field v-model="state.tel" clearable type="tel" label="手机号" placeholder=" 请输入您的手机号" />
      <van-field
        v-model="state.address"
        is-link
        readonly
        label="地区"
        placeholder="请选择所在地区"
        @click="state.show = true"
      />
      <van-popup v-model:show="state.show" round position="bottom">
        <van-cascader
          v-model="state.cascaderValue"
          title="请选择所在地区"
          placeholder="中国大陆"
          :options="options"
          @close="state.show = false"
          @finish="onFinish"
        />
      </van-popup>
      <van-field v-model="state.addressdetail" clearable label="详细地址" placeholder="小区楼栋/乡村名称" />
      <van-cell center title="设为默认">
        <template #right-icon>
          <van-switch v-model="state.checked" active-color="#FE8813" inactive-color="#dcdee0" size="24" />
        </template>
      </van-cell>
    </div>
    <div class="addNewAddress-footer">
      <van-button :disabled="state.disabled">保存</van-button>
      <!-- 保存 -->
    </div>
  </div>
</template>

<script>
import custom from '@/components/custom.vue'
import { reactive } from 'vue'
export default {
  components: {
    custom
  },
  setup() {
    const state = reactive({
      text: '',
      tel: '',
      address: '',
      addressdetail: '',
      checked: true,
      disabled: true,
      show: false
    })
    const options = [
      {
        text: '浙江省',
        value: '330000',
        children: [{ text: '杭州市', value: '330100' }]
      },
      {
        text: '江苏省',
        value: '320000',
        children: [{ text: '南京市', value: '320100' }]
      }
    ]
    const onFinish = ({ selectedOptions }) => {
      console.log(selectedOptions)
      state.show = false
      state.address = selectedOptions.map((option) => option.text).join('/')
    }
    return { state, options, onFinish }
  },
  data() {
    return {
      custom: {
        isSelect: false,
        isKeyboard: false,
        value: ''
      }
    }
  },
  created() {},
  methods: {
    onGetPay(val) {
      this.custom.value = val
    },
    onRest() {
      this.custom.isKeyboard = false
    }
  }
}
</script>

<style scoped lang="less">
.addNewAddress-header {
  height: 19px;
  background-color: #f2f2f2;
}
.addNewAddress-footer {
  text-align: center;
  margin-top: 130px;
  ::v-deep .van-button__content {
    width: 630px;
    height: 80px;
    background: linear-gradient(90deg, #ef3814 0%, #ff8d13 100%);
    // opacity: 0.3;
    border-radius: 10px;
    font-size: 28px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    line-height: 50px;
    text-align: center;
    line-height: 80px;
    margin: 0 auto;
    // margin-top: 130px;
  }
}

::v-deep .van-switch__node {
  width: 0.8em;
  height: 0.8em;
  top: 0.1em;
  left: 0.1em;
}
</style>
